package com.jayanslow.lighting.server;

import java.io.IOException;

import com.jayanslow.lighting.server.clients.ClientManager;
import com.jayanslow.lighting.server.dmx.DmxController;
import com.jayanslow.lighting.server.dmx.OverflowException;



public class LightingServer {
	/**
	 * @param args
	 * @throws OverflowException
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		DmxController dmx = new DmxController();
		log("DMX ready");
		ClientManager cman = new ClientManager();
		log("Client Manager ready");
		Server server = new Server(cman);
		server.start();
		log("Network Server ready");
		while (System.in.available() == 0) {
			if (cman.hasCommand()) cman.getCommand().run(dmx);
		}
		System.out.println("Stopping Server");
		server.end();
		log("Network Server stopped");
		dmx.stopFades();
		dmx.getSerial().disconnect();
		log("DMX stopped");
	}
	
	public static final boolean DEBUG_MODE = true;
	public static final boolean LOG_MODE = true;
	public static void debug(String s) {
		if (DEBUG_MODE) System.out.println(s);
	}
	public static void log(String s) {
		if (LOG_MODE) System.out.println(s);
	}
}